package com.cf.main;

import java.util.ArrayList;
import java.util.List;

public class ComputeSimilarity {
	public double computeSimilarity(int[] item1, int[] item2) {
		List<Integer> list1 = new ArrayList<Integer>();
		List<Integer> list2 = new ArrayList<Integer>();
		
		int length = 0;
		if (item1.length < item2.length) 
			length = item1.length;
		else 
			length = item2.length;
		// 仅对共同评价的项目计算相似度
		for (int i = 0; i < length; i++) {
			if (item1[i] != 0 && item2[i] != 0) {
				list1.add(new Integer(item1[i]));
				list2.add(new Integer(item2[i]));
			}
		}
		// 计算用户相似性
		return new PearsonCorrelation().pearsonCorrelation(list1, list2);
	}

}
